<!DOCTYPE html>
<html lang="en">

<head>
	<meta http-equiv="content-type" content="text/html; charset=utf-8">
	<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
	
	<!-- title -->
	
	<title>
	
		Spring基础 | 
	 
	对线面试官
	</title>
	
	<!-- keywords,description -->
	 
		<meta name="description" content="Java一线大厂面试" />
	

	<!-- favicon -->
	
	<link rel="shortcut icon" href="/luffy/favicon.ico">
	


	<!-- search -->
	<script>
		var searchEngine = "https://www.baidu.com/s?wd=";
		if(typeof searchEngine == "undefined" || searchEngine == null || searchEngine == ""){
			searchEngine = "https://www.google.com/search?q=";
		}
		var homeHost = "";
		if(typeof homeHost == "undefined" || homeHost == null || homeHost == ""){
			homeHost = window.location.host;
		}
	</script>


	
<link rel="stylesheet" href="/luffy/css/main.css">

	
<link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/4.7.0/css/font-awesome.min.css">

	
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.17.1/build/styles/darcula.min.css">

	
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.css">


	
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script>

	
<script src="https://cdn.jsdelivr.net/gh/fancyapps/fancybox@3.5.7/dist/jquery.fancybox.min.js"></script>

	
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@9.17.1/build/highlight.min.js"></script>

	
<script src="https://cdn.jsdelivr.net/npm/jquery-pjax@2.0.1/jquery.pjax.min.js"></script>

	
<script src="/luffy/js/main.js"></script>

	
		
<script src="https://cdn.jsdelivr.net/npm/leancloud-storage/dist/av-min.js"></script>

		
<script src="https://cdn.jsdelivr.net/npm/valine@1.3.10/dist/Valine.min.js"></script>

	
	
<meta name="generator" content="Hexo 5.4.0"></head>

<body>
	<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?3efe99c287df5a1d6f0d02d187e403c1";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

<header id="header">
    <a id="title" target="_blank" rel="noopener" href="https://mp.weixin.qq.com/mp/appmsgalbum?__biz=MzU4NzA3MTc5Mg==&action=getalbum&album_id=1657204970858872832&scene=126#wechat_redirect" class="logo">对线面试官</a>

	<ul id="menu">
		
	

	

		<li class="menu-item">
			<a href="https://gitee.com/zhongfucheng/Java3y" class="menu-item-link" target="_blank">
				【戳这里】获取更多原创干货💪💪
			</a>
		</li>
		<li class="menu-item">
			<a href="https://gitee.com/zhongfucheng/Java3y" class="menu-item-link" target="_blank">
				<i class="fa fa-github fa-2x"></i>
			</a>
		</li>
	</ul>
</header>

	
<div id="sidebar">
	<button id="sidebar-toggle" class="toggle" ><i class="fa fa-arrow-right " aria-hidden="true"></i></button>
	
	<div id="site-toc">
		<input id="search-input" class="search-input" type="search" placeholder="按回车全站搜索">
		<div id="tree">
			

			
							<ul>
								<li class="directory">
									<a href="#" class="directory">
										<i class="fa fa-plus-square-o"></i>
										00-面试前准备
									</a>
									
							<ul>
								<li class="file">
									<a href="/luffy/2021/10/30/00-%E9%9D%A2%E8%AF%95%E5%89%8D%E5%87%86%E5%A4%87/01.%E7%AE%80%E5%8E%86/">
										01.简历
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
								</li>
								
							</ul>
			
							<ul>
								<li class="directory">
									<a href="#" class="directory">
										<i class="fa fa-plus-square-o"></i>
										01-Java基础
									</a>
									
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/01-Java%E5%9F%BA%E7%A1%80/01.%20%E6%B3%A8%E8%A7%A3/">
										01. 注解
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/01-Java%E5%9F%BA%E7%A1%80/02.%20%E6%B3%9B%E5%9E%8B/">
										02. 泛型
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/01-Java%E5%9F%BA%E7%A1%80/03.%20JavaNIO/">
										03. JavaNIO
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/01-Java%E5%9F%BA%E7%A1%80/04.%20%E5%8F%8D%E5%B0%84%E5%92%8C%E5%8A%A8%E6%80%81%E4%BB%A3%E7%90%86/">
										04. 反射和动态代理
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
								</li>
								
							</ul>
			
							<ul>
								<li class="directory">
									<a href="#" class="directory">
										<i class="fa fa-plus-square-o"></i>
										02-Java并发
									</a>
									
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/02-Java%E5%B9%B6%E5%8F%91/01.%20%E5%A4%9A%E7%BA%BF%E7%A8%8B%E5%9F%BA%E7%A1%80/">
										01. 多线程基础
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/02-Java%E5%B9%B6%E5%8F%91/02.%20CAS/">
										02. CAS
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/02-Java%E5%B9%B6%E5%8F%91/03.%20synchronized/">
										03. synchronized
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/02-Java%E5%B9%B6%E5%8F%91/04.%20AQS%E5%92%8CReentrantLock/">
										04. AQS和ReentrantLock
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/02-Java%E5%B9%B6%E5%8F%91/05.%20%E7%BA%BF%E7%A8%8B%E6%B1%A0/">
										05. 线程池
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/02-Java%E5%B9%B6%E5%8F%91/06.%20ThreadLocal/">
										06. ThreadLocal
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/02-Java%E5%B9%B6%E5%8F%91/07.%20CountDownLatch%E5%92%8CCyclicBarrier/">
										07. CountDownLatch和CyclicBarrier
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/02-Java%E5%B9%B6%E5%8F%91/08.%20%E4%B8%BA%E4%BB%80%E4%B9%88%E9%9C%80%E8%A6%81Java%E5%86%85%E5%AD%98%E6%A8%A1%E5%9E%8B/">
										08. 为什么需要Java内存模型
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/02-Java%E5%B9%B6%E5%8F%91/09.%20%E6%B7%B1%E5%85%A5%E6%B5%85%E5%87%BAJava%E5%86%85%E5%AD%98%E6%A8%A1%E5%9E%8B/">
										09. 深入浅出Java内存模型
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
								</li>
								
							</ul>
			
							<ul>
								<li class="directory">
									<a href="#" class="directory">
										<i class="fa fa-plus-square-o"></i>
										03-Java容器
									</a>
									
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/03-Java%E5%AE%B9%E5%99%A8/01.%20List%E9%9B%86%E5%90%88/">
										01. List集合
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/03-Java%E5%AE%B9%E5%99%A8/02.%20Map%E9%9B%86%E5%90%88/">
										02. Map集合
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
								</li>
								
							</ul>
			
							<ul>
								<li class="directory">
									<a href="#" class="directory">
										<i class="fa fa-plus-square-o"></i>
										04-Java虚拟机
									</a>
									
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/04-Java%E8%99%9A%E6%8B%9F%E6%9C%BA/01.%20Java%E7%BC%96%E8%AF%91%E5%88%B0%E6%89%A7%E8%A1%8C%E7%9A%84%E8%BF%87%E7%A8%8B/">
										01. Java编译到执行的过程
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/04-Java%E8%99%9A%E6%8B%9F%E6%9C%BA/02.%20%E5%8F%8C%E4%BA%B2%E5%A7%94%E6%B4%BE%E6%9C%BA%E5%88%B6/">
										02. 双亲委派机制
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/04-Java%E8%99%9A%E6%8B%9F%E6%9C%BA/03.%20JVM%E5%86%85%E5%AD%98%E7%BB%93%E6%9E%84/">
										03. JVM内存结构
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/04-Java%E8%99%9A%E6%8B%9F%E6%9C%BA/04.%20%E5%9E%83%E5%9C%BE%E5%9B%9E%E6%94%B6%E6%9C%BA%E5%88%B6/">
										04. 垃圾回收机制
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/20/04-Java%E8%99%9A%E6%8B%9F%E6%9C%BA/05.%20CMS%E5%9E%83%E5%9C%BE%E6%94%B6%E9%9B%86%E5%99%A8/">
										05. CMS垃圾收集器
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/20/04-Java%E8%99%9A%E6%8B%9F%E6%9C%BA/06.%20G1%E5%9E%83%E5%9C%BE%E6%94%B6%E9%9B%86%E5%99%A8/">
										06. G1垃圾收集器
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/24/04-Java%E8%99%9A%E6%8B%9F%E6%9C%BA/07.%20JVM%E8%B0%83%E4%BC%98/">
										07. JVM调优
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
								</li>
								
							</ul>
			
							<ul>
								<li class="directory">
									<a href="#" class="directory">
										<i class="fa fa-plus-square-o"></i>
										05-Spring
									</a>
									
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/05-Spring/01.%20SpringMVC/">
										01. SpringMVC
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file active">
									<a href="/luffy/2021/08/19/05-Spring/02.%20Spring%E5%9F%BA%E7%A1%80/">
										02. Spring基础
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/05-Spring/03.%20SpringBean%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F/">
										03. SpringBean生命周期
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
								</li>
								
							</ul>
			
							<ul>
								<li class="directory">
									<a href="#" class="directory">
										<i class="fa fa-plus-square-o"></i>
										06-Redis
									</a>
									
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/06-Redis/01.%20Redis%E5%9F%BA%E7%A1%80/">
										01. Redis基础
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/06-Redis/02.%20Redis%E6%8C%81%E4%B9%85%E5%8C%96/">
										02. Redis持久化
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/20/06-Redis/03.%20Redis%E4%B8%BB%E4%BB%8E%E6%9E%B6%E6%9E%84/">
										03. Redis主从架构
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/20/06-Redis/04.%20Redis%E5%88%86%E7%89%87%E9%9B%86%E7%BE%A4/">
										04. Redis分片集群
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
								</li>
								
							</ul>
			
							<ul>
								<li class="directory">
									<a href="#" class="directory">
										<i class="fa fa-plus-square-o"></i>
										07-消息队列
									</a>
									
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/07-%E6%B6%88%E6%81%AF%E9%98%9F%E5%88%97/01.%20Kafka%E5%9F%BA%E7%A1%80/">
										01. Kafka基础
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/07-%E6%B6%88%E6%81%AF%E9%98%9F%E5%88%97/02.%20%E4%BD%BF%E7%94%A8Kafka%E4%BC%9A%E8%80%83%E8%99%91%E4%BB%80%E4%B9%88%E9%97%AE%E9%A2%98/">
										02. 使用Kafka会考虑什么问题
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
								</li>
								
							</ul>
			
							<ul>
								<li class="directory">
									<a href="#" class="directory">
										<i class="fa fa-plus-square-o"></i>
										08-MySQL
									</a>
									
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/08-MySQL/01.%20MySQL%E7%B4%A2%E5%BC%95/">
										01. MySQL索引
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/08-MySQL/02.%20MySQL%E4%BA%8B%E5%8A%A1%E5%92%8C%E9%94%81%E6%9C%BA%E5%88%B6%E5%92%8CMVCC/">
										02. MySQL事务和锁机制和MVCC
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/19/08-MySQL/03.%20MySQL%E8%B0%83%E4%BC%98/">
										03. MySQL调优
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
								</li>
								
							</ul>
			
							<ul>
								<li class="directory">
									<a href="#" class="directory">
										<i class="fa fa-plus-square-o"></i>
										09-项目场景类
									</a>
									
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/20/09-%E9%A1%B9%E7%9B%AE%E5%9C%BA%E6%99%AF%E7%B1%BB/01.%20%E5%A6%82%E4%BD%95%E5%AE%9E%E7%8E%B0%E5%8E%BB%E9%87%8D%E5%92%8C%E5%B9%82%E7%AD%89/">
										01. 如何实现去重和幂等
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/20/09-%E9%A1%B9%E7%9B%AE%E5%9C%BA%E6%99%AF%E7%B1%BB/02.%20%E7%B3%BB%E7%BB%9F%E9%9C%80%E6%B1%82%E5%A4%9A%E5%8F%98%E5%A6%82%E4%BD%95%E8%AE%BE%E8%AE%A1/">
										02. 系统需求多变如何设计
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/20/09-%E9%A1%B9%E7%9B%AE%E5%9C%BA%E6%99%AF%E7%B1%BB/03.%20%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/">
										03. 设计模式
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
								</li>
								
							</ul>
			
							<ul>
								<li class="directory">
									<a href="#" class="directory">
										<i class="fa fa-plus-square-o"></i>
										10-计算机网络
									</a>
									
							<ul>
								<li class="file">
									<a href="/luffy/2021/08/25/10-%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C/01.%20HTTP/">
										01. HTTP
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/10/13/10-%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C/02.TCP%E4%B8%89%E6%AC%A1%E6%8F%A1%E6%89%8B%E5%92%8C%E5%9B%9B%E6%AC%A1%E6%8C%A5%E6%89%8B/">
										02.TCP三次握手和四次挥手
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
								</li>
								
							</ul>
			
							<ul>
								<li class="directory">
									<a href="#" class="directory">
										<i class="fa fa-plus-square-o"></i>
										11-算法
									</a>
									
							<ul>
								<li class="file">
									<a href="/luffy/2021/09/01/11-%E7%AE%97%E6%B3%95/01.%20%E6%8E%92%E5%BA%8F%E7%AE%97%E6%B3%95/">
										01. 排序算法
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/09/02/11-%E7%AE%97%E6%B3%95/02.%20LeetCode%20Easy/">
										02. LeetCode Easy
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/09/02/11-%E7%AE%97%E6%B3%95/02.%20LeetCode%20Medium/">
										02. LeetCode Medium
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
								</li>
								
							</ul>
			
							<ul>
								<li class="directory">
									<a href="#" class="directory">
										<i class="fa fa-plus-square-o"></i>
										12-austin项目
									</a>
									
							<ul>
								<li class="file">
									<a href="/luffy/2021/11/01/12-austin%E9%A1%B9%E7%9B%AE/00.%E9%A1%B9%E7%9B%AE%E4%BB%8B%E7%BB%8D/">
										00.项目介绍
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/10/30/12-austin%E9%A1%B9%E7%9B%AE/01.%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/">
										01.环境搭建
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/10/30/12-austin%E9%A1%B9%E7%9B%AE/02.%E6%97%A5%E5%BF%97/">
										02.日志
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/11/24/12-austin%E9%A1%B9%E7%9B%AE/03.%E5%B7%A5%E5%85%B7%E5%8C%85/">
										03.工具包
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/11/24/12-austin%E9%A1%B9%E7%9B%AE/04.%E4%BB%8E%E4%B8%80%E6%9D%A1%E7%9F%AD%E4%BF%A1%E5%BC%80%E5%A7%8B/">
										04.从一条短信开始
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/11/24/12-austin%E9%A1%B9%E7%9B%AE/05.%E9%80%89%E6%8B%A9%E6%95%B0%E6%8D%AE%E5%BA%93%E5%92%8C%E6%8A%80%E6%9C%AF%E9%80%89%E5%9E%8B/">
										05.选择数据库和技术选型
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/11/24/12-austin%E9%A1%B9%E7%9B%AE/06.MySQL%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/">
										06.MySQL环境搭建
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
							<ul>
								<li class="file">
									<a href="/luffy/2021/11/24/12-austin%E9%A1%B9%E7%9B%AE/07.Kafka%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA/">
										07.Kafka环境搭建
									</a>
								</li>
								<div class="article-toc" style="display: none;"></div>
							</ul>
			
								</li>
								
							</ul>
			
		</div>
	</div>
</div>

	<!-- 引入正文 -->
	<div id="content">
		<h1 id="article-title">

	02. Spring基础
</h1>
<div class="article-meta">
	
	<span>3y</span>
	<span>2021-08-19 15:30:37</span>
		<div id="article-categories">
    
		<span>Categories：</span>
            
    

    
		<span>Tags：</span>
            
    
		</div>

</div>

<div id="article-content">
	<p><span style="color:#ab4642"><strong>面试官</strong></span>：我看到你的简历写着熟悉Spring</p>
<p><span style="color:#ab4642"><strong>面试官</strong></span>：<strong>要不你来讲讲Spring 的IOC和AOP你是怎么理解的呗？</strong></p>
<p><span style="color:#000080"><strong>候选者</strong></span>：嗯嗯，IOC和AOP是Spring非常核心的知识点</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：我就先来讲讲Spring IOC？</p>
<p><img src="https://tva1.sinaimg.cn/large/008i3skNgy1gtytcm665zj60j606a74n02.jpg"></p>
<p><span style="color:#ab4642"><strong>面试官</strong></span>：嗯</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：我个人理解下：Spring IOC 解决的是对象管理和对象依赖的问题。</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：本来是我们自己手动new出来的对象，现在则把对象交给Spring的IOC容器管理</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：IOC容器可以理解为一个对象工厂，我们都把该对象交给工厂，工厂管理这些对象的创建以及依赖关系</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：等我们需要用对象的时候，从工厂里边获取就好了</p>
<p><span style="color:#ab4642"><strong>面试官</strong></span>：嗯，说起IOC，就可以在网上或书籍经常看到的两个概念</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：哦，你说的就是「控制反转」和「注入依赖」吧？</p>
<p><span style="color:#ab4642"><strong>面试官</strong></span>：你怎么还抢答的咯…<strong>那你顺便说说你对这两个概念的理解呗？</strong></p>
<p><span style="color:#000080"><strong>候选者</strong></span>：我认为「控制反转」指的就是：把原有自己掌控的事交给别人去处理</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：它更多的是一种思想或者可以理解为设计模式</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：比如：本来由我们自己new出来的对象，现在交由IOC容器，把对象的控制权交给它方了</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：而「依赖注入」在我的理解下，它其实是「控制反转」的实现方式</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：对象无需自行创建或者管理它的依赖关系，依赖关系将被「自动注入」到需要它们的对象当中去</p>
<p><img src="https://tva1.sinaimg.cn/large/008i3skNgy1gtytddt7gzj612e074gn002.jpg"></p>
<p><span style="color:#ab4642"><strong>面试官</strong></span>：嗯，那我想问问，<strong>用Spring IOC有什么好处吗？</strong></p>
<p><span style="color:#ab4642"><strong>面试官</strong></span>：<strong>或者换个问法：本来我可以new出来的对象，为什么我要交由Spring IOC容器 管理呢？</strong></p>
<p><span style="color:#000080"><strong>候选者</strong></span>：主要的好处在于「将对象集中统一管理」并且「降低耦合度」</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：如果<span style="color:#ab4642"><strong>面试官</strong></span>理解了「工厂模式」，那就知道为什么我们不直接new对象</p>
<p><span style="color:#ab4642"><strong>面试官</strong></span>：好家伙，<strong>不行，这答案我观众不满意！</strong></p>
<p><span style="color:#000080"><strong>候选者</strong></span>：要说理由的话，可以举很多例子，比如说：</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：我用Spring IOC 可以方便 单元测试、对象创建复杂、对象依赖复杂、单例等等的，什么都可以交给Spring IOC</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：理论上自己new出来的都可以解决上面的问题，Spring在各种场景组合下有可能不是最优解</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：但new出来的你要自己管理，可能你得自己写工厂，得实现一大套的东西才能满足需求</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：写着写着有可能还是Spring的那一套</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：但现在Spring现在已经帮你实现了啊！</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：如果项目里的对象都是就new下就完事了，没有多个实现类，那没事，不用Spring也没啥问题</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：并且Spring核心不仅仅IOC啊，除了把对象创建出来，还有一整套的Bean生命周期管理</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：比如说你要实现对象增强，AOP不就有了吗？不然你还得自己创建代理..</p>
<p><img src="https://tva1.sinaimg.cn/large/008i3skNgy1gtyteokbgxj618204ymyf02.jpg"></p>
<p><span style="color:#ab4642"><strong>面试官</strong></span>：好好好</p>
<p><span style="color:#ab4642"><strong>面试官</strong></span>：但我看这届观众好像还是不太满意？</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：不，他们已经满意了。</p>
<p><span style="color:#ab4642"><strong>面试官</strong></span>：<strong>那你继续来聊下Spring AOP呗？</strong></p>
<p><span style="color:#000080"><strong>候选者</strong></span>：Spring AOP 解决的是 非业务代码抽取的问题</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：AOP 底层的技术是动态代理，在Spring内实现依赖的是BeanPostProcessor</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：比如我们需要在方法上注入些「重复性」的非业务代码，就可以利用Spring AOP</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：所谓的「面向切面编程」在我理解下其实就是在方法前后增加非业务代码</p>
<p><img src="https://tva1.sinaimg.cn/large/008i3skNgy1gtytfecdmij60vq04qq3q02.jpg"></p>
<p><span style="color:#ab4642"><strong>面试官</strong></span>：<strong>那你在工作中实际用到过AOP去优化你的代码吗？</strong></p>
<p><span style="color:#000080"><strong>候选者</strong></span>：有的。当时我用AOP来对我们公司现有的监控客户端进行封装</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：一个系统离不开监控，监控基本的指标有QPS、RT、ERROR等等</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：对外暴露的监控客户端只能在代码里写对应的上报信息（灵活，但会与业务代码掺杂在一起）</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：于是我利用注解+AOP的方式封装了一把，只要方法/类上带有我自定义的注解</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：方法被调用时，就会上报AQS、RT等信息</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：实现了非业务代码与业务代码分离的效果（：</p>
<p><img src="https://tva1.sinaimg.cn/large/008i3skNgy1gtythhqop7j60tu060q3t02.jpg"></p>
<p><span style="color:#ab4642"><strong>面试官</strong></span>：<strong>你们项目一般是怎么把对象交给IOC容器管理的？</strong></p>
<p><span style="color:#ab4642"><strong>面试官</strong></span>：换个问法：<strong>一般是怎么定义Bean的？</strong></p>
<p><span style="color:#000080"><strong>候选者</strong></span>：Spring提供了4种方式，分别是：</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：1):注解     2):XML    3):JavaConfig     4):基于Groovy DSL配置</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：一般项目我们用注解或XML比较多，少部分用JavaConfig</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：日常写业务代码一般用注解来定义各种对象，责任链这种一般配置在XML，「注解」解决不了的就用JavaConfig</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：总体而言，还是得看项目的代码风格吧（：</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：反正就是定义元数据，能给到Spring解析就好了</p>
<p><img src="https://tva1.sinaimg.cn/large/008i3skNgy1gtytit2g53j60um09qt9t02.jpg"></p>
<p><span style="color:#ab4642"><strong>面试官</strong></span>：嗯，了解。</p>
<p><span style="color:#ab4642"><strong>面试官</strong></span>：要不来聊聊你使用Spring的感受？</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：嗯嗯..</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：当我还是初学Spring的时候，我觉得Spring很麻烦，需要有一大堆的配置信息才能跑起来</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：光是搭建环境就需要耗费我好长的时间</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：毕竟版本冲突，依赖冲突什么的就可能一个下午就过去了</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：但毕竟一个系统环境只搭一次嘛，所以还好</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：（后来用上了SpringBoot这又更方便了）</p>
<p><img src="https://tva1.sinaimg.cn/large/008i3skNgy1gtytj6pgxrj60uo04ijre02.jpg"></p>
<p><span style="color:#ab4642"><strong>面试官</strong></span>：嗯…</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：话说回来，IOC和AOP在工作用的时候还是很爽的</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：毕竟搞个注解什么的，配置下就可以把对象交给Spring管理了</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：配合Spring的生态，@Transactional注解什么的，都好用得飞起</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：不过，Spring给我们封装得太好了</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：经常就会有奇奇怪怪的”bug“出现，也踩过很多的坑了</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：Bean经常没办法创建成功，导致项目启动失败</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：对象的循环依赖问题…</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：同一个接口，多个实现，识别不出我要创建哪个对象…</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：为什么catch了异常，Spring事务为什么还会自动回滚</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：等等等…..</p>
<p><img src="https://tva1.sinaimg.cn/large/008i3skNgy1gtytjr5p5dj60v405eaad02.jpg"></p>
<p><span style="color:#000080"><strong>候选者</strong></span>：总的来说，Spring给我们封装了一个很好的环境，实现对我们屏蔽了</p>
<p><span style="color:#000080"><strong>候选者</strong></span>：但是如果理解不深的话，很有可能就会触发各种bug</p>
<p><span style="color:#ab4642"><strong>面试官</strong></span>：了解</p>
<p><img src="https://tva1.sinaimg.cn/large/008i3skNgy1gtm4w73nyzj61030tztbp02.jpg"></p>
<p><span align="center">第一时间获取<span style="color:#000080"><strong>BATJTMD一线互联网大厂</strong></span>最新的面试资料以及内推机会关注公众号<span style="color:#ab4642"><strong>「对线<span style="color:#ab4642"><strong>面试官</strong></span>」</strong></span></p>
<img align="center" src='https://tva1.sinaimg.cn/large/008i3skNgy1gtlvty8zo5j60u00u0q5602.jpg' width=300px height=300px />







 

</div>


    <div class="post-guide">
        <div class="item left">
            
              <a href="/luffy/2021/08/19/05-Spring/03.%20SpringBean%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F/">
                  <i class="fa fa-angle-left" aria-hidden="true"></i>
                  03. SpringBean生命周期
              </a>
            
        </div>
        <div class="item right">
            
              <a href="/luffy/2021/08/19/05-Spring/01.%20SpringMVC/">
                01. SpringMVC
                <i class="fa fa-angle-right" aria-hidden="true"></i>
              </a>
            
        </div>
    </div>




<script>
	
	
</script>
	</div>
	<button id="totop-toggle" class="toggle"><i class="fa fa-angle-double-up" aria-hidden="true"></i></button>
</body>
</html>
